home *** CD-ROM | disk | FTP | other *** search
- Path: das-news2.harvard.edu!das-news!tlb
- From: tlb@chardonnay.eecs.harvard.edu (Trevor Blackwell)
- Newsgroups: comp.lang.c++
- Subject: parsing inline method definitions
- Date: 04 Mar 1996 19:12:42 -0500
- Organization: Harvard
- Sender: tlb@chardonnay.eecs.harvard.edu
- Message-ID: <vqevikk8kjo.fsf@chardonnay.eecs.harvard.edu>
- Reply-To: tlb@eecs.harvard.edu
- NNTP-Posting-Host: chardonnay.harvard.edu
- X-Disclaimer:
-
-
- Is it possible to construct parse trees of inline method declarations
- at the time they are read?
-
- Here's an example to show why it might be hard. If an instance
- variable 'foo' shadows a class name 'foo', it changes the parsing of
- 'foo *x'. This declaration of the instance variables can follow the
- inline declaration.
-
- I can't believe the two would be represented the same in a parse tree.
-
- I guess you could save the inline declaration as a pure token stream,
- and then parse it later. What does, say gcc do? (I don't want to read
- the code.)
-
- The code below prints 8 and 1 on my system (gcc alpha-OSF1-V3.0).
-
- class foo {
- public:
- };
-
- class bar1 {
- public:
- func() {
- char x;
- {
- foo * x; // x is pointer to foo
- printf("%d\n",sizeof(x));
- }
- }
- };
-
- class bar2 {
- public:
- func() {
- char x;
- {
- foo * x; // multiply foo by x
- printf("%d\n",sizeof(x));
- }
- }
- int foo; // shadows class foo
- };
-
- main()
- {
- bar1 b1;
- bar2 b2;
-
- b1.func();
- b2.func();
- }
-
- --
- --
- Trevor Blackwell tlb@eecs.harvard.edu (617) 495-8912
- http://www.eecs.harvard.edu/~tlb
-